package com.servlet.webqq.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class MethodUtil {
	private static final String SET = "set";
	private static final String GET = "get";
	public static Method[] filterSetMethod(Method[] methods){
		List<Method> met = new ArrayList<Method>();
		for(Method temp:methods){
			if(temp.getName().startsWith(SET))
				met.add(temp);
		}
		return  met.toArray(new Method[0]);
	}
	public static Method[] filterGetMethod(Method[] methods) {
		List<Method> met = new ArrayList<Method>();
		for(Method temp:methods){
			if(temp.getName().startsWith(GET))
				met.add(temp);
		}
		return  met.toArray(new Method[0]);
	}
	public static List<String> clipSetHead(Method[] method){
		List<String> arrayList = new ArrayList<String>();
		String name = null;
		for(Method temp:method){
			name = temp.getName();
			arrayList.add(name.substring(3,name.length()));
		}
		return arrayList;
	}
	public static Method  isSetMethod(Class<?> objClass, String name) {
		try {
			return objClass.getDeclaredMethod(SET+name,String.class);
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
		return null; 
	}
}
